from selenium.webdriver.common.by import By
from unittestWeb.common.publicmethod import PublicMethod


class LoginPage(PublicMethod):

    def send_phone(self, phone):
        '''输入手机号'''
        self.sendKeys((By.XPATH, '//*[@placeholder="手机号" and @type="tel"]'), phone, is_full=True)

    def send_password(self, password):
        '''输入密码'''
        self.sendKeys((By.ID, 'password'), password, is_full=True)

    def click_agreement(self):
        '''点击协议'''
        self.click((By.XPATH, '//*[@data-testid="protocolCheckBox"]'))

    def click_login(self):
        '''点击登录按钮'''
        self.click((By.XPATH, '//*[@data-aspm-click="d009"]'))

    def text_judge(self, text):
        '''判断是否登录成功'''
        self.text_to_be_present_in_element((By.XPATH, '(//*[@class="badge-module_memberBadgeNameCon_PlSXK"])[1]'), text)

    def normal_login(self, **kwargs):
        '''正常登录流程'''
        self.send_phone(kwargs["phone"])
        self.send_password(kwargs["password"])
        self.click_agreement()
        self.click_login()


